package com.saa.common.utils;

import java.util.List;

public class Page<T> {
    /***每页显示数**/
    private int pageSize;
    /***页码***/
    private int pageNum;
    /***总页数***/
    private int totalCount;
    /**当前页**/
    private int preNum;
    /**当前首页**/
    private int startNum;
    /**当前尾页**/
    private int EndNum;
    /**返回集合数据**/
    private List<T> list;
    /**总数据量**/
    private int totalSize;

    public Page(int pageSize, int preNum, List<T>list){
        this.pageSize=pageSize;
        this.preNum=preNum;
        this.totalCount=(list.size()+pageSize-1)/pageSize;
        this.totalSize=list.size();
        this.pageNum=preNum;
        this.startNum=1;
        this.EndNum=totalCount;
        int firstIndex = (preNum-1)*pageSize;//数组上标
        int lastIndex = preNum*pageSize;//数组下标
        if(lastIndex>list.size()){
            lastIndex = list.size();
        }
        this.list=list.subList(firstIndex,lastIndex);

    }

    public Page() {

    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPreNum() {
        return preNum;
    }

    public void setPreNum(int preNum) {
        this.preNum = preNum;
    }

    public int getStartNum() {
        return startNum;
    }

    public void setStartNum(int startNum) {
        this.startNum = startNum;
    }

    public int getEndNum() {
        return EndNum;
    }

    public void setEndNum(int endNum) {
        EndNum = endNum;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

}

